package com.demo.java.OD401_450.OD423;

import java.util.*;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【石头剪刀布游戏(C&D卷)】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146261391
 */
public class OdMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<String, List<String>> moveMap = new HashMap<>();

        // 读取输入数据
        while (scanner.hasNext()) {
            String player = scanner.next(); // 读取玩家ID
            String move = scanner.next();   // 读取玩家出拳 (A, B, C)

            // 将玩家加入对应出拳类别的列表中
            moveMap.putIfAbsent(move, new ArrayList<>());
            moveMap.get(move).add(player);
        }

        // 仅有1种或3种出拳方式，则无胜者
        if (moveMap.size() == 1 || moveMap.size() == 3) {
            System.out.println("NULL");
            return;
        }

        // 确定哪种出拳方式胜出
        List<String> winners;
        if (moveMap.containsKey("A") && moveMap.containsKey("B")) {
            winners = moveMap.get("A"); // A > B
        } else if (moveMap.containsKey("B") && moveMap.containsKey("C")) {
            winners = moveMap.get("B"); // B > C
        } else {
            winners = moveMap.get("C"); // C > A
        }

        // 按字典序排序赢家ID
        Collections.sort(winners);
        for (String winner : winners) {
            System.out.println(winner);
        }
    }
}
